/*
 * Copyright (c) 2010-2017 EEFUNG Software Co.Ltd. All rights reserved. 版权所有(c)2010-2017湖南蚁坊软件有限公司。保留所有权利。
 */
package com.spring.ribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述,该部分必须以中文句号结尾。
 *
 * @author panqingcui
 * @create 2017-02-20 16:36
 */
@RestController
public class ConsumerController {
//    @Autowired
//    RestTemplate restTemplate;
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add() {
//        System.out.println("************core"+restTemplate.getForEntity("http://CORE/info",String.class).getBody());
//
//        System.out.println("*********spring-cloud-service-server"+restTemplate.getForEntity("http://spring-cloud-service-server/add?a=10&b=20", String.class).getBody());
//        return restTemplate.getForEntity("http://spring-cloud-service-server/add?a=10&b=20", String.class).getBody();
        System.out.println("**********spring-cloud-service-server:"+loadBalancerClient.choose("spring-cloud-service-server1").getUri());
        System.out.println("****"+ loadBalancerClient.choose("spring-cloud-service-server").getHost());
        System.out.println(loadBalancerClient.choose("spring-cloud-service-server").getMetadata());
        //System.out.println("************core:"+loadBalancerClient.choose("CORE").getUri());
        return loadBalancerClient.choose("spring-cloud-service-server").getUri().toString();

    }

    @RequestMapping("/greeting")
    public String greeting(@RequestParam(value = "name", required = false, defaultValue = "World") String name,
            Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}
